<template>
	<view>
		<view class='commission-details'>
			<view class='promoterHeader bg-color'>
				<view class='headerCon acea-row row-between-wrapper'>
					<view>
						<view class='name'>{{name}}</view>
						<view class='money' v-if="recordType == 1">￥<text class='num'>{{userInfo.total_extract}}</text></view>
						<view class='money' v-if="recordType == 2">￥<text class='num'>{{userInfo.brokerage_price}}</text></view>
					</view>
					<view class='iconfont icon-jinbi1'></view>
				</view>
			</view>
			<view class='sign-record' v-if="type==1">
					<block v-for="(item,index) in recordList" :key="index" v-if="recordList.length>0">
						<view class='list'>
							<view class='item'>
								<!-- <view class='data'>{{item.create_time}}</view> -->
								<view class='listn'>
									<view class='itemn acea-row row-between-wrapper'>
										<view>
											<block v-if="item.status>=0">
												<view class='name line1' v-if="item.extract_type == 0">银行卡提现</view>
												<view class='name line1' v-if="item.extract_type == 1">微信提现</view>
												<view class='name line1' v-if="item.extract_type == 2">支付宝提现</view>
											</block>
											<block v-else>
												<view class='name line1'>提现失败</view>
											</block>
											<view>{{item.create_time}}</view>
										</view>
										<view class='num' v-if="item.status>=0">-{{item.extract_price}}</view>
										<view class='num font-color' v-else>+{{item.extract_price}}</view>
										
									</view>
								</view>
							</view>
						</view>
					</block>
				<view v-if="recordList.length == 0">
					<emptyPage title='暂无提现记录~'></emptyPage>
				</view>
			</view>
			<view class='list' v-if="type==2">
				<block v-for="(item,index) in recordList" :key="index" v-if="recordList.length>0">
						<view class='item'>
							<!-- <view class='data'>{{item.create_time}}</view> -->
							<view class='listn'>
								<view class='itenm'>
									<view class='top acea-row row-between-wrapper'>
										<view class='pictxt acea-row row-between-wrapper'>
											<view class='pictrue'>
												<image :src='item.avatar?item.avatar:"/static/images/headPortrait.png"'></image>
											</view>
											<view class='text line1'>{{item.nickname}}</view>
										</view>
										<view class='money'>
											<text class='font-color' v-if="item.type==2">￥{{item.money}}</text>
											<text class='font-color2' v-else>￥{{item.money}}</text>
										</view>
									</view>
									<view class='bottom'>
										<view><text class='name'></text>{{item.type==2?'推广补贴':'推广收益'}}</view>
										<view><text class='name'>下单时间：</text>{{item.ctime}}</view>
									</view>
								</view>
							</view>
						</view>
				</block>
				<view v-if="recordList.length == 0">
					<emptyPage title='暂无补贴记录~'></emptyPage>
				</view>
			</view>
		</view>
		<!-- #ifdef MP -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		<!-- #endif -->
	</view>
</template>

<script>
	// #ifdef MP
	import authorize from '@/components/Authorize';
	// #endif
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			// #ifdef MP
			authorize,
			// #endif
			emptyPage
		},
		data() {
			return {
				name: '',
				type: 0,
				page: 0,
				limit: 15,
				recordList: [],
				recordType: 0,
				recordCount: 0,
				status: false,
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false, //是否隐藏授权
				extractCount: 0,
				userInfo:'',
			};
		},
		onLoad(options) {
				this.type = options.type;
		},
		onShow: function() {
			let type = this.type;
			
			if(type == 2){
				uni.setNavigationBarTitle({
					title: "补贴记录"
				});
				this.name = '补贴明细';
				this.recordType = 2;
			}
			if(type == 1){
				uni.setNavigationBarTitle({
					title: "提现记录"
				});
				this.name = '提现总额';
				this.recordType = 1;
			}
			this.spreadInfo();
			this.getRecordList();
			// this.getRecordListCount();
		},
		methods: {
			spreadInfo(){
				this.$api.spreadInfo( res => {
					this.userInfo = res.data
				})
			},
			onLoadFun() {
				this.isShowAuth = false;
				this.getRecordList();
				// this.getRecordListCount();
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			getRecordList: function() {
				let that = this;
				let page = that.page;
				let limit = that.limit;
				let status = that.status;
				let recordType = that.recordType;
				let recordList = that.recordList;
				let recordListNew = [];
				if (status == true) return;
				if(this.type == 1){
					that.$api.extractLst({
						page: page,
						limit: limit
					},res => {
						let len = res.data.list.length;
						let recordListData = res.data.list;
						recordListNew = recordList.concat(recordListData);
						that.status = limit > len;
						that.page+=1;
						that.$set(that, 'recordList', recordListNew);
					})
				}
				if(this.type == 2){
					that.$api.spreadOrder({
						page: page,
						limit: limit
					},res => {
						let len = res.data.list.length;
						let recordListData = res.data.list;
						recordListNew = recordList.concat(recordListData);
						that.status = limit > len;
						that.page+=1;
						that.$set(that, 'recordList', recordListNew);
					})
				}
			},
			getRecordListCount: function() {
				let that = this;
				that.$api.getSpreadInfo( res => {
					that.recordCount = res.data.commissionCount;
					that.extractCount = res.data.extractCount;
				})
			}
		},
		onReachBottom: function() {
			this.page++
			this.getRecordList();
		}
	}
</script>

<style scoped lang="scss">
	.commission-details .promoterHeader .headerCon {
		    width: 100%;
		    height: 220rpx;
		    padding: 0 44px 0 27px;
		    box-sizing: border-box;
		    font-size: 28rpx;
		    color: #fff;
			background-image: url(../../../static/images/post-bg.png);
		    background-repeat: no-repeat;
		    background-size: 100% 100%;
	}
	.commission-details .promoterHeader .headerCon .name {
	    margin-bottom: 10rpx;
	}
	.commission-details .promoterHeader .headerCon .iconfont {
	    font-size: 124rpx;
	}
	
	.commission-details .promoterHeader .headerCon .money {
		font-size: 36rpx;
	}

	.commission-details .promoterHeader .headerCon .money .num {
		font-size: 50rpx;
		font-family: 'Guildford Pro';
	}
	.commission-details .list .item{
		margin-bottom: 20rpx;
	}
	.commission-details .list .item .listn {
	    background-color: #fff;
	    font-size: 24rpx;
	    color: #999;
	}
	.commission-details .list .item .listn .itenm {
		background-color: #fff;
	}

	.commission-details .list .item .listn .itenm~.itenm {
		margin-top: 12rpx;
	}

	.commission-details .list .item .listn .itenm .top {
		margin-left: 30rpx;
		padding-right: 30rpx;
		border-bottom: 1rpx solid #eee;
		height: 100rpx;
	}

	.commission-details .list .item .listn .itenm .top .pictxt {
		width: 320rpx;
	}

	.commission-details .list .item .listn .itenm .top .pictxt .text {
		width: 230rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.commission-details .list .item .listn .itenm .top .pictxt .pictrue {
		width: 66rpx;
		height: 66rpx;
	}

	.commission-details .list .item .listn .itenm .top .pictxt .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		border: 3rpx solid #fff;
		box-sizing: border-box;
		box-shadow: 0 0 15rpx #aaa;
	}

	.commission-details .list .item .listn .itenm .top .money {
		font-size: 28rpx;
	}

	.commission-details .list .item .listn .itenm .bottom {
		padding: 20rpx 30rpx;
		font-size: 28rpx;
		color: #666;
		line-height: 1.6;
	}

	.commission-details .list .item .listn .itenm .bottom .name {
		color: #999;
	}
	.font-color2 {
		color: #F96E29;
	}
</style>
